#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define INFINITY 65535
#define vex_num 2021
typedef struct MGraph{
	int vexs[2021];
	int arc[2021][2021];
}MGraph;
typedef int Patharc[2021];
typedef int Patharc_s[2021][2021];
typedef int ShortPathTable[2021];
typedef int ShortPathTable_s[2021][2021];
int LCM(int a, int b){
	int x = a,y=b;
	while (a % b != 0)
	{
		int temp = a % b;
		a = b;
		b = temp;
	}
	return (x * y / b);
}
void InitGraph(MGraph* G) {
	for (int i = 0; i < 2021; i++) {
		G->vexs[i] = i + 1;
		for (int j = 0; j < 2021; j++) {
			if (i - j <= 21 && i - j >= 0 || j - i <= 21 && j - i >= 0)
				G->arc[i][j] = LCM(i + 1, j + 1);
			else
				G->arc[i][j] = INFINITY;
		}
	}
}
void ShortestPath(MGraph* G, int v0, Patharc* P, ShortPathTable* D) {
	int final[2021];
	int k,w;
	for (int v = 0; v < 2021; v++) {
		final[v] = 0;
		(*D)[v] = G->arc[v0][v];
		(*P)[v] = -1;
	}
	final[v0] = 1;
	(*D)[v0] = 0;
	for (int v = 1; v < 2021; v++) {
		int min = INFINITY;
		for (w = 0; w < 2021; w++)
		{
			if (G->arc[v][w] < min&&final[w]==0) {
				min = G->arc[v][w];
				min = (*D)[w];
				k = w;
			}
		}
		final[k] = 1;
		for (w = 0; w < 2021; w++) {
			if (final[w] == 0 && min + G->arc[k][w] < (*D)[w]) {
				(*D)[w] = min + G->arc[k][w];
				(*P)[w] = k;
			}
		}
	}
}


int main()
{
	MGraph* G = (MGraph*)malloc(sizeof(MGraph));
	InitGraph(G);
	Patharc P;
	ShortPathTable D;
	ShortestPath(G, 0, &P, &D);
	printf("%d", D[2020]);
	return 0;
}